<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        .strengthLv0 {
            width: 300px;
            height: 50px;
            border: 1px solid #000;
        }
        
        .strengthLv1 {
            width: 300px;
            height: 50px;
            background: red;
        }
        
        .strengthLv2 {
            width: 300px;
            height: 50px;
            background: green;
        }
        
        .strengthLv3 {
            width: 300px;
            height: 50px;
            background: blue;
        }
    </style>

</head>

<body>
    <input type="text" id="pwd">
    <div id="strengthLevel" class="strengthLv0"></div>
    <script>
        pwd.onkeyup = function() {
            if (this.value.length >= 6) {
                var lvl = getLvl(this.value);
                strengthLevel.className = "strengthLv" + lvl;
                if (lvl == 1) {
                    strengthLevel.innerHTML = "弱"
                } else if (lvl == 2) {
                    strengthLevel.innerHTML = "中强"
                } else {
                    strengthLevel.innerHTML = "强"
                }
            } else {
                strengthLevel.className = "strengthLv0";
            }
        }

        function getLvl(pwd) {
            var lvl = 0;
            var str = '';
            //密码中是否有数字，或者是字母，或者是特殊符号
            if (/[0-9]/.test(pwd)) {
                lvl++;
            }
            //判断密码有没有字母
            if (/[a-zA-Z]/.test(pwd)) {
                lvl++;
            }
            //判断密码中有没有特殊符号
            if (/[^0-9a-zA-Z]/.test(pwd)) {
                lvl++;
            }
            return lvl;
        }
    </script>
</body>

</html>